package com.xjk.controller;

import com.alibaba.fastjson.JSONObject;
import com.xjk.bean.FcBuilding;
import com.xjk.bean.FcEstate;
import com.xjk.bean.TblCompany;
import com.xjk.pojo.ResultOverallObject;
import com.xjk.service.EstateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Xjk
 */

@RestController
public class EstateController {

    @Autowired
    private EstateService estateService;

    @RequestMapping("/estate/selectCompany")
    public String selectCompany(){
        List<TblCompany> tblCompanies = estateService.selectCompanies();
        return JSONObject.toJSONString(new ResultOverallObject(tblCompanies));
    }

    @RequestMapping("/estate/insertEstate")
    public String insertEstate(FcEstate fcEstate){
        Integer integer = estateService.insertEstate(fcEstate);
        if(integer==0){
            return JSONObject.toJSONString(new ResultOverallObject("插入房产失败","0"));
        }else{
            return JSONObject.toJSONString(new ResultOverallObject("插入房产成功","1"));
        }
    }

    @RequestMapping("/estate/selectBuilding")
    public String selectBuilding(Integer buildingNum,String estateCode){
        List<FcBuilding> fcBuildings = estateService.selectBuilding(buildingNum, estateCode);
        return JSONObject.toJSONString(new ResultOverallObject(fcBuildings));
    }

}
